package com.example.module_maintenance.viewmodel

import androidx.lifecycle.MutableLiveData
import com.bw.lib_common.coroutine.CoroutineHelper
import com.bw.lib_common.vm.BaseViewModel2
import com.example.module_maintenance.entity.PublishNewsEntity
import com.example.module_maintenance.repo.AddCultureRepo
import kotlinx.coroutines.launch
import okhttp3.RequestBody

class AddNewsViewModel : BaseViewModel2<AddCultureRepo>(){
    val addCultureSuccess by lazy { MutableLiveData<PublishNewsEntity>() }


    fun addCulture(body: RequestBody){
        CoroutineHelper.mViewModelScope.launch ( CoroutineHelper.mDispatcher ){
            val result = mRepository.addCulture(body)
            if (result.code==200){
                addCultureSuccess.postValue(result.data)
            }else{
                mErrorLiveData.postValue("添加失败")
            }
        }
    }






    override fun createRepository(): AddCultureRepo = AddCultureRepo()


}